/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-04-03 21:08:26
 * @LastEditTime: 2024-06-30 18:24:02
 * @FilePath: /nest_study/web/src/components/show_drawer/index.tsx
 */
import { Button, Drawer, Space, Spin } from "antd";
import styles from './index.module.scss'
import { CloseOutlined } from '@ant-design/icons';
import { MacScrollbar } from "mac-scrollbar";
import 'mac-scrollbar/dist/mac-scrollbar.css';

const DrawerWrapper = (props: any) => {
    let { children, title = '基本信息', placement = "right", loading = false, width = 540, isShow = true, cancelText = '取消', submitText = '确定', isSubmit = true, footer } = props;

    const onClose = () => {
        props.close();
    }

    const onSubmit = () => {
        props.submit()
    }
    return (
        <Drawer
            title={title}
            placement={placement}
            width={width}
            onClose={onClose}
            closable={false}
            open={isShow}
            maskClosable={false}
            extra={
                <Space>
                    <Button type="text" onClick={onClose}><CloseOutlined /></Button>
                </Space>
            }
            footer={
                (footer || footer === false) ? footer : (
                    <Space className={styles.control_footer}>
                        <Button type="primary" ghost onClick={onClose}>{cancelText}</Button>
                        {
                            isSubmit && <Button type="primary" onClick={onSubmit}>{submitText}</Button>
                        }
                    </Space>
                )
            }
        >
            <MacScrollbar skin="dark" className={`${styles.drawer_body}`}>
                <Spin spinning={loading}>
                    {children}
                </Spin>
            </MacScrollbar>
        </Drawer>
    );
};

export default DrawerWrapper;
